home *** CD-ROM | disk | FTP | other *** search
- /*
- * httpd.h: header for simple (ha! not anymore) http daemon
- */
-
- #ifndef AMIGA
- #define VOID_PARMS /*none*/
- #else
- #define VOID_PARMS void
- #endif
-
- /* Define one of these according to your system. */
- #if defined(SUNOS4)
- #define BSD
- #undef NO_KILLPG
- #undef NO_SETSID
- char *crypt(char *pw, char *salt);
-
- #elif defined(SOLARIS2)
- #undef BSD
- #define NO_KILLPG
- #undef NO_SETSID
- #define bzero(a,b) memset(a,0,b)
-
- #elif defined(IRIX)
- #undef BSD
- #undef NO_KILLPG
- #undef NO_SETSID
-
- #elif defined(HPUX)
- #undef BSD
- #define NO_KILLPG
- #undef NO_SETSID
-
- #elif defined(AIX)
- #undef BSD
- #undef NO_KILLPG
- #undef NO_SETSID
-
- #elif defined(ULTRIX)
- #define BSD
- #undef NO_KILLPG
- #undef NO_SETSID
- #define ULTRIX_BRAIN_DEATH
- #define NEED_STRDUP
-
- #elif defined(OSF1)
- #define BSD
- #undef NO_KILLPG
- #undef NO_SETSID
-
- #elif defined(SEQUENT)
- #define BSD
- #undef NO_KILLPG
- #define NO_SETSID
- #define NEED_STRDUP
- #define tolower(c) (isupper(c) ? tolower(c) : c)
-
- #elif defined(NEXT)
- #define BSD
- #undef NO_KILLPG
- #define NO_SETSID
- #define NEED_STRDUP
- #define _POSIX_SOURCE
- #define S_ISDIR(m) (((m)&(S_IFMT)) == (S_IFDIR))
- #define S_ISREG(m) (((m)&(S_IFMT)) == (S_IFREG))
- #define S_IXUSR 00100
- #define S_IXGRP 00010
- #define S_IXOTH 00001
- #define STDIN_FILENO 0
- #define STDOUT_FILENO 1
- #define STDERR_FILENO 2
- #define waitpid(a,b,c) wait4(a,b,c,NULL)
- #define NEED_PUTENV
- typedef int pid_t;
-
- #elif defined(LINUX)
- #undef BSD
- #undef NO_KILLPG
- #undef NO_SETSID
- #undef NEED_STRDUP
-
- #elif defined(SCO)
- #undef BSD
- #undef NO_KILLPG
- #undef NO_SETSID
- #define NEED_INITGROUPS
-
- #elif defined(CONVEXOS)
- #define BSD
- #define NEED_STRDUP
-
- #elif defined(AUX)
- #undef BSD
- #undef NO_KILLPG
- #undef NO_SETSID
- #define NEED_STRDUP
- #define _POSIX_SOURCE
-
- #elif defined(AMIGA)
- #define BSD
- #define NO_KILLPG
- #define NO_SETSID
- #define NO_NCSA_EXEC
- #define NO_INCLUDE_COMMANDS
- /*#define NO_SECURITY*/
- #undef NEED_STRDUP
- /*#define NEED_INITGROUPS*/
- #define COLON_SEPARATOR
- #define _POSIX_SOURCE
- #define strcasecmp stricmp
- #define strncasecmp strnicmp
- #define SIGKILL SIGTERM
- #define S_ISDIR(m) (((m)&(S_IFMT)) == (S_IFDIR))
- #define S_ISREG(m) (((m)&(S_IFMT)) == (S_IFREG))
- #define S_IXUSR 00100
- #define S_IXGRP 00010
- #define S_IXOTH 00001
- #define STDIN_FILENO 0
- #define STDOUT_FILENO 1
- #define STDERR_FILENO 2
- #define fprintf __SaFprintf
- #define fclose __SaFclose
- #define fwrite __SaFwrite
- #define fputs __SaFputs
- #define fputc __SaFputc
- #define fflush __SaFflush
-
- /* Unknown system - Edit these to match */
- #else
- /* BSD is whether your system uses BSD calls or System V calls. */
- #define BSD
- /* NO_KILLPG is set on systems that don't have killpg */
- #undef NO_KILLPG
- /* NO_SETSID is set on systems that don't have setsid */
- #undef NO_SETSID
- /* NEED_STRDUP is set on stupid systems that don't have strdup. */
- #undef NEED_STRDUP
- #endif
-
- /*
- * The particular directory style your system supports. If you have dirent.h
- * in /usr/include (POSIX) or /usr/include/sys (SYSV), #include
- * that file and define DIR_TYPE to be dirent. Otherwise, if you have
- * /usr/include/sys/dir.h, define DIR_TYPE to be direct and include that
- * file. If you have neither, I'm confused.
- */
- #if !defined(NEXT) && !defined(CONVEXOS)
- #include <dirent.h>
- #define DIR_TYPE dirent
- #else
- #include <sys/dir.h>
- #define DIR_TYPE direct
- #endif
-
- /* ----------------------------- config dir ------------------------------ */
-
- /* Define this to be the default server home dir. Anything later in this
- * file with a relative pathname will have this added.
- */
- #define HTTPD_ROOT "/usr/local/etc/httpd"
- #ifdef AMIGA
- #undef HTTPD_ROOT
- #define HTTPD_ROOT "http:"
- #endif
- /* Root of server */
- #define DOCUMENT_LOCATION "/usr/local/etc/httpd/htdocs"
- #ifdef AMIGA
- #undef DOCUMENT_LOCATION
- #define DOCUMENT_LOCATION "http:htdocs"
- #endif
-
- /* Max. number of aliases */
- #define MAX_ALIASES 20
-
- /* Max. number of security defines */
- #define MAX_SECURITY 50
-
- /* Max. number of include files */
- #define MAXINCLUDES 20
-
- #ifdef AMIGA
- /* Max. number of groups (whatever these are ) */
- #define NGROUPS_MAX (20)
- #endif
-
- /* Default administrator's address */
- #define DEFAULT_ADMIN "[no address given]"
-
- /*
- * --------- You shouldn't have to edit anything below this line ----------
- *
- * Any modifications to any defaults not defined above should be done in the
- * respective config. file.
- *
- */
-
-
- /* -------------- Port number for server running standalone --------------- */
-
- #define DEFAULT_PORT 80
-
- /* --------- Default user name and group name running standalone ---------- */
- /* --- These may be specified as numbers by placing a # before a number --- */
-
- #define DEFAULT_USER "#-1"
- #define DEFAULT_GROUP "#-1"
-
- /* The name of the log files */
- #define DEFAULT_XFERLOG "logs/access_log"
- #define DEFAULT_ERRORLOG "logs/error_log"
- #define DEFAULT_PIDLOG "logs/httpd.pid"
-
- /* Define this to be what your HTML directory content files are called */
- #define DEFAULT_INDEX "index.html"
-
- /* Define this to be what type you'd like returned for files with unknown */
- /* suffixes */
- #define DEFAULT_TYPE "text/html"
-
- /* Define this to be what your per-directory security files are called */
- #define DEFAULT_ACCESS_FNAME ".htaccess"
-
- /* The name of the server config file */
- #define SERVER_CONFIG_FILE "conf/httpd.conf"
-
- /* The name of the document config file */
- #define RESOURCE_CONFIG_FILE "conf/srm.conf"
-
- /* The name of the MIME types file */
- #define TYPES_CONFIG_FILE "conf/mime.types"
-
- /* The name of the access file */
- #define ACCESS_CONFIG_FILE "conf/access.conf"
-
-
- /* The default directory in user's home dir */
- #define DEFAULT_USER_DIR "public_html"
-
-
- /* The default string lengths */
- #define MAX_STRING_LEN 256
- #define HUGE_STRING_LEN 8192
-
- /* The timeout for waiting for messages */
- #define DEFAULT_TIMEOUT 1200
-
-
- /* ------------------------------ error types ------------------------------ */
-
- #define SERVER_VERSION "NCSA/1.0"
- #define SERVER_PROTOCOL "HTTP/1.0"
- #define SERVER_SUPPORT "httpd@ncsa.uiuc.edu"
-
- #define REDIRECT 302
- #define BAD_REQUEST 400
- #define AUTH_REQUIRED 401
- #define FORBIDDEN 403
- #define NOT_FOUND 404
- #define SERVER_ERROR 500
- #define NOT_IMPLEMENTED 501
- #define INCLUDE_ERROR 6991
-
- #define METHODS 3
- #define M_GET 0
- #define M_PUT 1
- #define M_POST 2
-
- /* Object types */
- #define REDIRECT_URL -1
- #define STD_DOCUMENT 0
- #define SCRIPT_NCSA 1
- #define SCRIPT_CGI 2
-
- #define OPT_NONE 0
- #define OPT_INDEXES 1
- #define OPT_INCLUDES 2
- #define OPT_SYM_LINKS 4
- #define OPT_ALL (OPT_INDEXES|OPT_INCLUDES|OPT_SYM_LINKS)
-
- #define OR_NONE 0
- #define OR_LIMIT 1
- #define OR_OPTIONS 2
- #define OR_FILEINFO 4
- #define OR_AUTHCFG 16
- #define OR_ALL (OR_LIMIT|OR_OPTIONS|OR_FILEINFO|OR_AUTHCFG)
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #ifndef AMIGA
- #include <sys/file.h>
- #endif
- #include <sys/socket.h>
- #include <ctype.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <sys/ioctl.h>
- #include <arpa/inet.h> /* for inet_ntoa */
- #include <time.h> /* for ctime */
- #include <signal.h>
- #include <errno.h>
- #ifndef AMIGA
- #include <sys/wait.h>
- #endif
- #include <pwd.h>
- #include <grp.h>
-
- #ifndef AMIGA
- #ifndef NEXT
- #include <unistd.h>
- #endif
- #endif
-
- #ifdef ultrix
- #define ULTRIX_BRAIN_DEATH
- #endif
-
- #ifdef AMIGA
- #ifdef AMITCP
- #include <inetdlib.h>
- #endif
- #endif
-
- /* Just in case your linefeed isn't the one the other end is expecting. */
- #define LF 10
- #define CR 13
-
- /* For access control */
- #define DENY_THEN_ALLOW 0
- #define ALLOW_THEN_DENY 1
-
- /* Struct shared by access and auth */
- typedef struct {
- char *d;
- char opts;
- char override;
-
- int order[METHODS];
-
- int num_allow[METHODS];
- char *allow[METHODS][MAX_SECURITY];
- int num_auth[METHODS];
- char *auth[METHODS][MAX_SECURITY];
-
- char *auth_type;
- char *auth_name;
- char *auth_pwfile;
- char *auth_grpfile;
-
- int num_deny[METHODS];
- char *deny[METHODS][MAX_SECURITY];
- } security_data;
-
- /* Globals */
-
- /* Server config */
- extern int standalone;
- extern int port;
- extern uid_t user_id;
- extern gid_t group_id;
- extern char server_root[MAX_STRING_LEN];
- extern char error_fname[MAX_STRING_LEN];
- extern char xfer_fname[MAX_STRING_LEN];
- extern char pid_fname[MAX_STRING_LEN];
- extern char server_admin[MAX_STRING_LEN];
- extern char *server_hostname;
- extern char server_confname[MAX_STRING_LEN];
- extern char srm_confname[MAX_STRING_LEN];
- extern char access_confname[MAX_STRING_LEN];
- extern char types_confname[MAX_STRING_LEN];
- extern int timeout;
-
- /* Document config */
- extern char user_dir[MAX_STRING_LEN];
- extern char index_name[MAX_STRING_LEN];
- extern char access_name[MAX_STRING_LEN];
- extern char document_root[MAX_STRING_LEN];
- extern char default_type[MAX_STRING_LEN];
-
- /* Security config */
- extern int num_sec;
- #ifndef AMIGA
- extern security_data sec[MAX_SECURITY];
- #else
- extern security_data __far sec[MAX_SECURITY];
- #endif
-
- /* Auth config */
- extern char *auth_type;
- extern char *auth_name;
- extern char *auth_pwfile;
- extern char *auth_grpfile;
- extern char user[MAX_STRING_LEN];
-
- /* Request information */
- extern char *remote_name;
- extern int assbackwards;
- extern int header_only;
- extern char *remote_host;
- extern char *remote_ip;
- extern char *remote_name;
- extern int allow;
- extern char allow_options;
- extern int num_includes;
-
- /* MIME */
- extern char auth_line[MAX_STRING_LEN];
- extern int content_length;
- extern char content_type[MAX_STRING_LEN];
- extern char location[MAX_STRING_LEN];
- extern char http_accept[HUGE_STRING_LEN];
- /* Function prototypes. */
-
- /* http_config */
- void read_config(VOID_PARMS);
- void parse_htaccess(char *dir, char override);
- int get_pw(char *user, char *pw);
- int in_group(char *user, char *group);
- int init_group(char *grpfile);
- void kill_group(VOID_PARMS);
-
- /* http_alias */
- void reset_aliases(VOID_PARMS);
- void dump_aliases(VOID_PARMS);
- void add_alias(char *f, char *r, int is_script);
- void add_redirect(char *f, char *url);
- int translate_name(char *name,FILE *fd);
- void unmunge_name(char *name);
-
- /* http_request */
- void process_request(int in, FILE *out);
- void send_fd(FILE *f, FILE *fd, char *args);
- void send_fd_timed_out(VOID_PARMS);
-
- /* http_get */
- void send_file(char *file,FILE *fd, char *args);
- void process_include(FILE *f, FILE *fd, char *incstring, char *args);
- void send_node(char *name, char *args, FILE *fd);
- void process_get(int in, FILE *out, char *m, char *url, char *args);
-
- /* http_put */
- void get_node(char *name, char *args, int in, FILE *out);
-
- /* http_script */
- void exec_cgi_script(char *method, char *path, char *args, int in, FILE *out);
- void exec_get_NCSA(char *path, char *args, FILE *fd);
- void exec_post_NCSA(char *path, char *args, int in, FILE *out);
-
- /* http_dir */
- extern void index_directory(char *name, FILE *fd);
-
- /* http_log */
- void log_transaction(char *cmd_line);
- void log_error(char *err);
- void log_reason(char *reason, char *file);
- void die(int type, char *err_string, FILE *fd);
- void open_logs(VOID_PARMS);
- void close_logs(VOID_PARMS);
-
- /* http_mime */
- void get_mime_headers(int fd);
- void send_mime_headers(FILE *fd);
- void set_content_type(char *fn);
- int scan_script_header(FILE *f, FILE *fd);
- void add_type(char *fn, char *t);
- void add_encoding(char *fn, char *t);
- void set_content_length(int l);
- void dump_types(VOID_PARMS);
- void init_mime(VOID_PARMS);
- void kill_mime(VOID_PARMS);
- int is_content_type(char *type);
- void dump_default_header(FILE *fd);
-
- /* http_access */
- void evaluate_access(char *path, struct stat *finfo,int m, int *allow,
- char *op);
- void kill_security(VOID_PARMS);
-
- /* http_auth */
- void check_auth(security_data *s, int m);
-
- /* util */
- void strsubfirst(int start,char *dest, char *src);
- void make_full_path(char *src1,char *src2,char *dst);
- int is_directory(char *name);
- void getparents(char *name);
- uid_t uname2id(char *name);
- gid_t gname2id(char *name);
- int getline(char *s, int n, int f, unsigned int timeout);
- int cfg_getline(char *s, int n, FILE *f);
- void getword(char *word, char *line, char stop);
- void cfg_getword(char *word, char *line);
- void get_remote_host(int fd);
- char *get_time(VOID_PARMS);
- char *gm_timestr_822(time_t t);
- void make_dirstr(char *s, int n, char *d);
- int count_dirs(char *path);
- void strcpy_dir(char *d, char *s);
- void unescape_url(char *url);
- void escape_url(char *url);
- void escape_shell_cmd(char *cmd);
- void plustospace(char *str);
- void spacetoplus(char *str);
- void str_tolower(char *str);
- void uudecode(char *s,unsigned char *d,int dl);
- #ifdef NEED_STRDUP
- char *strdup (char *str);
- #endif
- #ifdef NEED_PUTENV
- void putenv(char *s);
- #endif
- void ht_putenv(char *n, char *v);
- int ind(char *s, char c);
- int rind(char *s, char c);
- void construct_url(char *d, char *s);
- void get_local_host(VOID_PARMS);
- int get_portnum(int sd,FILE *out);
- int can_exec(struct stat *finfo);
- #ifdef NEED_INITGROUPS
- int initgroups(const char *name, gid_t basegid);
- #endif
- #ifdef NEED_ALARM
- void alarm(int timeout);
- #endif
-